import { fileURLToPath, URL } from 'url'

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'

import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
// https://vitejs.dev/config/
export default defineConfig({

    server: {
        host: '0.0.0.0',
        port: 3003,
        proxy: {
            '^/api': {
                target: 'http://localhost:8888',
                rewrite: (path) => path.replace(/^\/api/, '')
            }
        }
    },
    css: {
        preprocessorOptions: {
            scss: {
                additionalData: `@use "~/styles/element.scss" as *;`,
            },
        },
    },
    plugins: [
        vue(),
        AutoImport({
            dts: false,
            imports: ['vue', 'vue-router'],
            resolvers: [ElementPlusResolver({
                importStyle: "sass",
            })],
        }),
        Components({
            dts: false,
            resolvers: [ElementPlusResolver({
                importStyle: "sass",
            })],
        }),
    ],
    resolve: {
        alias: {
            '@': fileURLToPath(new URL('./src', import.meta.url)),
            '~': fileURLToPath(new URL('./src', import.meta.url))
        }
    },
    optimizeDeps: {
        include: [
            "element-plus/es/components/rate/style/index",
            "element-plus/es/components/radio-group/style/index",
            "element-plus/es/components/radio/style/index",
            "element-plus/es/components/col/style/index",
            "element-plus/es/components/popconfirm/style/index",
            "element-plus/es/components/card/style/index",
            "element-plus/es/components/tag/style/index",
            "element-plus/es/components/row/style/index",
            "element-plus/es/components/switch/style/index",
            "element-plus/es/components/color-picker/style/index",
            "element-plus/es/components/tabs/style/index",
            "element-plus/es/components/tab-pane/style/index",
            "element-plus/es/components/breadcrumb/style/index",
            "element-plus/es/components/message-box/style/index",
            "element-plus/es/components/tree/style/index",
            "element-plus/es/components/breadcrumb-item/style/index",
            "element-plus/es/components/checkbox/style/index",
            "element-plus/es/components/checkbox-group/style/index",
            "element-plus/es/components/message/style/index",
            "element-plus/es/components/option-group/style/index"
        ]
    }
})